//
//  photoScrollView.m
//  项目一
//
//  Created by nick on 15/7/23.
//  Copyright (c) 2015年 nick. All rights reserved.
//

#import "photoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation photoScrollView{
    UIImageView *imageView;
}
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.delegate = self;
        self.maximumZoomScale = 3;
        self.minimumZoomScale = 1;
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTapAction)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTapAction)];
        singleTap.numberOfTouchesRequired = 1;
        singleTap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:singleTap];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
    }

    return self;
}
- (void)singleTapAction{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"hidenNavigationBar" object:nil];
}
- (void)doubleTapAction{
    if (self.zoomScale == 1) {
        [self setZoomScale:3];
    }
    else if (self.zoomScale == 3){
        [self setZoomScale:1];
    }
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

    return imageView;
    
}

- (void)setImageUrl:(NSString *)imageUrl{
    _imageUrl = imageUrl;
    [self setNeedsLayout];
}
- (void)layoutSubviews{
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl]];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
